package ru.ifmo.ipimenov.ewf_svn.standalone.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Document;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.State;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Rules;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.list.StateModel;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.list.RulesModel;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.RulesProvider;
import ru.ifmo.ipimenov.ewf_svn.standalone.service.DocumentService;
import ru.ifmo.ipimenov.ewf_svn.standalone.service.RulesService;
import ru.ifmo.ipimenov.ewf_svn.standalone.service.impl.DocumentServiceImpl;
import ru.ifmo.ipimenov.ewf_svn.standalone.service.impl.RulesServiceImpl;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author: Ilya Pimenov
 * Scartel Starlab company
 */
public class RemoveRuleAction implements ActionListener {
    /**
     * Logger for all purposes
     */
    private static Log log = LogFactory.getLog(ProcessAction.class);

    private JList list;

    public RemoveRuleAction(JList list) {
        this.list = list;
    }

    public void actionPerformed(ActionEvent e) {
        RulesModel m = (RulesModel) list.getModel();
        Rules r = m.getRules(list.getSelectedIndex());

        RulesService rs = new RulesServiceImpl();
        rs.delete(r);

        m.remove(r);
        list.updateUI();
    }

}